<template>
    <div class="user-edit h-100" v-loading="loading">
      222
        <!-- Drawer抽屉 -->
        <div class="drawer-content h-100">
          <Col span="24">
            <Form ref="searchForm" :model="dictDataList" :label-width="labelWidth" class="marginForm">
              <FormItem label="单位名称" >
                <Input type="text" v-model="searchForm.name" clearable placeholder="请输入单位名称" style="width: 100%"
                       @click.prevent="$event.preventDefault()"/>
              </FormItem>
              <FormItem label="经营状态" >
                <Select v-model="searchForm.status" clearable
                        style="width: 100%">
                  <Option v-for="item in statusList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
              </FormItem>
              <FormItem label="统一社会信用代码" >
                <Input type="text" v-model="searchForm.code" clearable placeholder="请输入统一社会信用代码" style="width: 100%"
                       @click.prevent="$event.preventDefault()"/>
              </FormItem>
              <FormItem label="单位性质" >
                <Select v-model="searchForm.nature" clearable style="width: 100%">
                  <Option v-for="(item,index) in unitNatureDicts" :value="item.value" :key="index">{{ item.title }}
                  </Option>
                </Select>
              </FormItem>
              <FormItem label="单位行业" >
                <Select v-model="searchForm.industry" clearable
                        style="width: 100%">
                  <Option v-for="(item,index) in unitIndustryDicts" :value="item.value" :key="index">{{ item.title }}
                  </Option>
                </Select>
              </FormItem>
            </Form>
          </Col>
        </div>
        <div class="br right-bottom-edit">
            <Button type="primary" :loading="submitLoading" @click="submit">提交</Button>
            <Button @click="cancel">取消</Button>
        </div>
    </div>
</template>

<script>
// 根据你的实际请求api.js位置路径修改
import { addBysXjCompare, editBysXjCompare, getDetailList } from '@/api/bys/xj/xjCompare.js';
import { getDictDataByType } from '@/api';
import { updatePersonInfoByIdAPI } from '../../../../api/bys/destinationAfterGraduation';
export default {
    name: 'compareDetail',
    components: {},
    props: {
        value: {
            type: Boolean,
            default: false
        },
        data: {
            type: Object
        },
      statusList:{
        type: Array,
        default: ()=>{
          return []
        }
      },
      unitNatureDicts:{
        type: Array,
        default: ()=>{
          return []
        }
      },
      unitIndustryDicts:{
        type: Array,
        default: ()=>{
          return []
        }
      },
    },
    data() {
        return {
          labelWidth: 110,
            loading: false,
            flag: '',
            props: ['id'],
            dictDataList: {
                cx: [],
                yxdm: [],
                xbdm: [],
                mzdm: [],
                zzmmdm: [],
                xldm: [],
                zyfx: [],
                xxxs: [],
                pyfsdm: [],
                syszddm: [],
                xz: [],
                sfslbdm: [],
                knslbdm: []
            },
            type:0,
            showWsy: false,
            title: '',
            submitLoading: false,
            maxHeight: 510,
            form: {
                // 添加或编辑表单对象初始化数据
            },
            bysId: '',
            detailData: [],
            // 表单验证规则
            formValidate: {}
        };
    },

    inject: ['getDataList'],
    methods: {
        submit() {
            this.loading = true;
            const formParams = {
                studentId: this.bysId,
                bysj: '', //毕业时间
                cxsy: '', //城乡生源
                sydCode: '', //生源地
                rxsj: '', //入学时间
                sfslbCode: '', //师范生类别
                zzmmCode: '', //政治面貌
                gxCode: '', //高校
                status: ''
            };
            formParams.status = this.data.status;
            console.log(formParams, 'formParams');
            console.log(this.detailData);
            this.detailData.forEach(item => {
                formParams[item.bysColumn] = item.bysData;
                // if (item.bysColumn === 'gxcode'){
                //     formParams.gxCode = item.sfslbCode
                // }
                // if (item.bysColumn === 'cxsy') {
                //   formParams[item.bysColumn] = item.sfslbCode
                // }
                // if (item.bysColumn === 'zzmmCode'){
                //   formParams[item.bysColumn] = item.sfslbCode
                // }
                // if (item.bysColumn === 'sfslbCode'){
                //   formParams[item.bysColumn] = item.sfslbCode
                // }
            });
            console.log(formParams);
            let dataForm = false;
            this.detailData.forEach(item => {
                if (item.bysData === item.xjData) {
                    dataForm = true;
                } else {
                    dataForm = false;
                }
            });
            console.log(dataForm, '...');
            updatePersonInfoByIdAPI(formParams)
                .then(res => {
                    if (res.success) {
                        this.$message.success(res.message);
                        this.loading = false;
                        this.$forceUpdate();
                        if (dataForm) {
                            this.$emit('open-search', true);
                            this.getDataList();
                        } else {
                            this.getDataList();
                        }
                    } else {
                        this.loading = false;
                    }
                })
                .catch(err => {
                    this.loading = false;
                });
        },
        // lenMin(text) {
        //   console.log(text)
        //   // let flag = true
        //   // text.trim()
        //   // if (flag && text.length >= max)
        // },
        init(type) {
          console.log(1,type);
        },
        getDetailContent() {
            this.showWsy = false;
            this.detailData = [];
            this.bysId = this.data.bysId;
            let cont = this.data.content;
            if (cont.includes('基础信息不存在')) {
                this.showWsy = true;
                return;
            }
            if (cont.charAt(cont.length - 2) === ',') {
                let strArray = cont.split(''); // 将字符串转换为字符数组
                strArray.splice(cont.length - 2, 1); // 从索引为1的位置开始删除一个字符
                cont = strArray.join(''); // 将字符数组转换回字符串
            }
            this.detailData = JSON.parse(cont);
            this.getDictDataList();
        },
        cancel(e) {
            this.$emit('open-search', true);
        },
        getDictDataList() {
            if (this.detailData.length > 0) {
                for (let i = 0; i < this.detailData.length; i++) {
                    console.log(this.detailData);

                    const nowDetail = this.detailData[i];
                    console.log(nowDetail);
                    if(nowDetail.description==="专业方向"){
                        this.detailData[i].isSelect = false;
                    }
                    if (nowDetail.xjColumn.includes('yxdm')) {
                        this.postRequest('/schoolCode/getAll').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.yxdm = res.result.map(e => {
                                    return {
                                        title: e.name,
                                        value: e.code
                                    };
                                });
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('xbdm')) {
                        //性别
                        getDictDataByType('sex').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.xbdm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('cx')) {
                        //性别
                        getDictDataByType('cxsy').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.cx = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('mzdm')) {
                        //民族
                        getDictDataByType('ethnic').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.mzdm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('zzmmdm')) {
                        //政治面貌
                        getDictDataByType('political').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.zzmmdm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('xldm')) {
                        //学历
                        getDictDataByType('degree').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.xldm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('zydm')) {
                        //   专业
                        // getDictDataByType('eduLevelType').then(res => {
                        //   if (res.success) {
                        //     this.this.detailData[i].dictData = res.result.map(item => ({...item, label:item.title, loading:false, children: []}))
                        //   }
                        // })
                    }
                    if (nowDetail.xjColumn.includes('xxxs')) {
                        //学习形式
                        getDictDataByType('learning-forms').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.xxxs = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('pyfsdm')) {
                        //培养方式
                        getDictDataByType('training-methods').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.pyfsdm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('syszddm')) {
                        //生源所在地
                        this.postRequest('/areaCode/getAll').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.syszddm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('xz')) {
                        //学制
                        getDictDataByType('educational-system').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.xz = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('sfslbdm')) {
                        //师范生类别
                        getDictDataByType('sfs_type').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.sfslbdm = res.result;
                            }
                        });
                    }
                    if (nowDetail.xjColumn.includes('knslbdm')) {
                        //困难生类别
                        getDictDataByType('difficult-student-category').then(res => {
                            if (res.success) {
                                // this.detailData[i].dictData
                                this.dictDataList.knslbdm = res.result;
                            }
                        });
                    }
                }
            }
        }
    },
    watch: {
        data(val) {
            this.getDetailContent();
        },
        visible(value) {
            this.$emit('input', value);
        }
    },
};
</script>

<style lang="less">
// 建议引入通用样式 具体路径自行修改 可删除下面样式代码
// @import "../../../styles/drawer-common.less";
.drawer-footer {
    z-index: 10;
    width: 100%;
    position: absolute;
    bottom: 0;
    left: 0;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: left;
    background: #fff;
}

.drawer-content {
    overflow: auto;
}

.drawer-content::-webkit-scrollbar {
    display: none;
}

.drawer-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    font-size: 16px;
    color: rgba(0, 0, 0, 0.85);
}

.drawer-title {
    font-size: 16px;
    color: rgba(0, 0, 0, 0.85);
    display: block;
    margin-bottom: 16px;
}

</style>
<style scoped lang="less">
/deep/ .br.right-bottom-edit {
    bottom: 25px !important;
}
/deep/ .ivu-form-item {
    display: block !important;
}
/deep/ .ivu-form-item-label {
    justify-content: left !important;
}
</style>
